package com.weitu.archives.personArchives.service.impl;

import com.weitu.accessory.util.AccessoryUtil;
import com.weitu.archives.personArchives.entity.SecurityMeetingLedger;
import com.weitu.archives.personArchives.mapper.SecurityMeetingLedgerMapper;
import com.weitu.archives.personArchives.service.SecurityMeetingLedgerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Created by smp on 2017/5/15.
 */
@Service
public class SecurityMeetingLedgerServiceImpl implements SecurityMeetingLedgerService{
    private final SecurityMeetingLedgerMapper securityMeetingLedgerMapper;
    @Autowired
    public SecurityMeetingLedgerServiceImpl(SecurityMeetingLedgerMapper securityMeetingLedgerMapper){
        this.securityMeetingLedgerMapper=securityMeetingLedgerMapper;
    }

    @Override
    public int queryCount(Map<String, Object> map) {
        return this.securityMeetingLedgerMapper.queryCount(map);
    }

    @Override
    public List<SecurityMeetingLedger> queryList(Map<String, Object> map) {
        return this.securityMeetingLedgerMapper.queryList(map);
    }

    @Override
    @Transactional
    public boolean insertSecurityMeetingLedger(SecurityMeetingLedger securityMeetingLedger) {
        int count=this.securityMeetingLedgerMapper.insertSecurityMeetingLedger(securityMeetingLedger);
        boolean flag= AccessoryUtil.saveAccerssoryInfo(securityMeetingLedger.getId());
        boolean flag2=false;
        if(count==1){
            flag2=true;
        }
        return flag&&flag2;
    }

    @Override
    public SecurityMeetingLedger querySecurityMeetingLedgerById(String id) {
        return this.securityMeetingLedgerMapper.querySecurityMeetingLedgerById(id);
    }

    @Override
    @Transactional
    public boolean updateSecurityMeetingLedger(SecurityMeetingLedger securityMeetingLedger) {
        int count=this.securityMeetingLedgerMapper.updateSecurityMeetingLedger(securityMeetingLedger);
        boolean flag= AccessoryUtil.saveAccerssoryInfo(securityMeetingLedger.getId());
        boolean flag2=false;
        if(count==1){
            flag2=true;
        }
        return flag&&flag2;
    }

    @Override
    public int deleteSecurityMeetingLedger(String id) {
        return this.securityMeetingLedgerMapper.deleteSecurityMeetingLedger(id);
    }
}
